﻿function showUser(username) {
	if (refreshWin('showUser_' + username))
		return;
	getUserInfo({
				username : username,
				success : onload
			});

	function onload(user) {
		var txtusername = new Ext.form.TextField({
					fieldLabel : '用户名',
					value : user.username
				});
		var nickname = new Ext.form.TextField({
					fieldLabel : '昵称',
					value : user.nickname
				});
		var email = new Ext.form.TextField({
					fieldLabel : 'Email',
					value : user.email
				});
		var motto = new Ext.form.TextField({
					fieldLabel : '座右铭',
					value : user.motto
				});
		var regTime = new Ext.form.TextField({
					fieldLabel : '注册时间',
					value : user.regTime
				});
		var lastLoginTime = new Ext.form.TextField({
					fieldLabel : '最后登录',
					value : user.lastLoginTime
				});
		var sid = new Ext.form.TextField({
					fieldLabel : '学号',
					value : user.sid
				});
		var name = new Ext.form.TextField({
					fieldLabel : '姓名',
					value : user.name
				});
		var school = new Ext.form.TextField({
					fieldLabel : '学校',
					value : user.school
				});
		var sex = new Ext.form.TextField({
					fieldLabel : '性别',
					value : sys.rd.sex(user.sex)
				});
		var birthday = new Ext.form.TextField({
					fieldLabel : '生日',
					value : user.birthday
				});
		var rank = new Ext.form.TextField({
					fieldLabel : '排名',
					value : user.rank
				});
		var submit = new Ext.form.TextField({
					fieldLabel : '提交次数',
					value : user.accept + ' / ' + user.submit + ' ('
							+ sys.rd.ratio(user.accept, user.submit) + ')'
				});
		var accept = new Ext.form.TextField({
					fieldLabel : '通过题数',
					value : user.problemAccept
				});

		var toolbar = new Ext.Toolbar({
					items : [new Ext.Button({
										text : '详细统计',
										iconCls : 'statistics-icon',
										handler : function() {
											showUserStatistics(user.username);
											win.close();
										}
									}), new Ext.Button({
										text : '查看提交',
										iconCls : 'status-icon',
										handler : function() {
											showStatusList({
														username : user.username
													});
											win.close();
										}
									})]
				});
		if (sys.user && username != sys.user.username)
			toolbar.add([new Ext.Button({
						text : '发送消息',
						iconCls : 'replymail-icon',
						disabled : !sys.canSendMsg,
						handler : function() {
							sendMsg(user.username);
							win.close();
						}
					})]);
		if (sys.user && username == sys.user.username || sys.god)
			toolbar.add([new Ext.Toolbar.Separator(), new Ext.Button({
								text : '修改资料',
								iconCls : 'editinfo-icon',
								handler : function() {
									editUser(user.username);
									win.close();
								}
							})]);
		toolbar.add([new Ext.Toolbar.Fill(), new Ext.Button({
							text : '关闭',
							iconCls : 'ok-icon',
							handler : function() {
								win.close()
							}
						})]);

		var form = new Ext.form.FormPanel({
					frame : true,
					border : false,
					labelWidth : 80,
					items : [new Ext.form.FieldSet({
								title : '基本资料',
								collapsible : true,
								defaults : {
									anchor : '100%',
									readOnly : true
								},
								items : [txtusername, nickname, email, motto,
										regTime, lastLoginTime]
							}), new Ext.form.FieldSet({
								title : '个人信息',
								checkboxToggle : true,
								collapsed : !user.publicPersonalInfo,
								defaults : {
									anchor : '100%',
									readOnly : true
								},
								items : [Ext.isEmpty(user.sid) ? {} : sid,
										name, school, sex, birthday]
							}), new Ext.form.FieldSet({
								title : '统计信息',
								collapsible : true,
								defaults : {
									anchor : '100%',
									readOnly : true
								},
								items : [rank, accept, submit]
							})]
				});

		var win = new Ext.Window({
					id : 'showUser_' + user.username,
					title : '查看资料 - ' + user.username,
					iconCls : 'userinfo-icon',
					width : 400,
					minWidth : 350,
					autoHeight : true,
					shadow : false,
					items : form,
					bbar : toolbar
				});
		win.show();
	}
}
